#include "stdafx.h"
#include "FiveWinnerChecker.h"

#include "../Strategy/ChessStatus.h"

FiveWinnerChecker::FiveWinnerChecker(const int chessSize):_chessSize(chessSize)
{
}

WinnerChecker::Winner FiveWinnerChecker::Check(ChessStatus* status) const
{
	typedef FiveInRow::Entity::ChessStatus FiveChessStatus;
	typedef FiveInRow::Entity::Piece FivePiece;

	FiveChessStatus^ fiveChessStatus = gcnew FiveChessStatus(_chessSize, _chessSize);
	vector<Point> allBlacks = status->GetAllBlacks();
	for (auto black : allBlacks)
	{
		FivePiece^ piece = gcnew FivePiece(black.X(), black.Y(), System::Drawing::Color::Black);
		fiveChessStatus->AddBlackPiece(piece);
	}
	vector<Point> allWhites = status->GetAllWhites();
	for (auto white : allWhites)
	{
		FivePiece^ piece = gcnew FivePiece(white.X(), white.Y(), System::Drawing::Color::White);
		fiveChessStatus->AddWhitePiece(piece);
	}

	if (fiveChessStatus->BlackWin())
	{
		return WinnerChecker::Black;
	}
	else if (fiveChessStatus->WhiteWin())
	{
		return WinnerChecker::White;
	}
	else
	{
		return WinnerChecker::None;
	}
}
